package com.java46.admin.order.service;



import com.java46.admin.order.dao.OrderDao;


import com.java46.admin.order.entity.AllOrders;
import com.java46.admin.user.util.Page;
import com.java46.front.base.exception.BusinessException;
import com.java46.front.order.entity.OrdersEntity;

import javax.persistence.criteria.CriteriaBuilder;
import java.util.List;

public class OrderService{
    private OrderDao orderDao=new OrderDao();
    //得到所有的订单
    public Page getAllOrders(String pageNo, String condition){
        if(pageNo==null||"".equals(pageNo)){
            pageNo="1";
        }
        if(condition==null){
            condition="";
        }
        Page page =new Page();
        //总记录数
        int allRow = orderDao.getOrdersCount(condition);
        //分页查询结果集
        page.setPageNo(Integer.parseInt(pageNo));
        page.setPageSize(5);
        page.setTotalRecords(allRow);
        //当前页开始记录
        int offset = page.countOffset(Integer.parseInt(pageNo),page.getPageSize());
        List<AllOrders> list = orderDao.getOrders(offset,page.getPageSize(),condition);
        page.setList(list);
        return page;
    }
    //删除订单
    public void deleteOrders(String orderId){
        if(orderId==null||"".equals(orderId)){
            throw new BusinessException("没有订单Id");
        }
        orderDao.deleteOrders(Integer.parseInt(orderId));
    }
    //订单详细信息
    public AllOrders getOrdersByOrderId(String orderId) {
        if(orderId==null||"".equals(orderId)){
            throw new BusinessException("没有订单Id");
        }
        return orderDao.getOrdersByOrderId(Integer.parseInt(orderId));

    }
}
